package com.hisense.ovcloud.commons.configs.vertx;

import io.netty.handler.logging.ByteBufFormat;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.core.net.NetServerOptions;
import io.vertx.core.net.PemKeyCertOptions;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
@Data
public class VertxDeploymentInit {
    private DeploymentOptions options = new DeploymentOptions();

    @Autowired
    private VertxDeploymentOptions optionsInYaml;

    @Bean
    public NetServerOptions initNetServerOptions() {
        return new NetServerOptions()
                .setSsl(true)
                .setPemKeyCertOptions(new PemKeyCertOptions()
                        .setKeyPath("/Users/edwin/WORKSPACE/CODE/JAVA17/ac-java/ac-julink/src/main/resources/cert/server.key")
                        .setCertPath("/Users/edwin/WORKSPACE/CODE/JAVA17/ac-java/ac-julink/src/main/resources/cert/server.pem"))
                .setLogActivity(true)
                .setActivityLogDataFormat(ByteBufFormat.SIMPLE);
    }

    @Bean
    public Vertx initVertx() {
        return Vertx.vertx();
    }

    @Bean
    public DeploymentOptions initOptions() {
        options.setInstances(optionsInYaml.getInstanceNum());
        options.setWorkerPoolName(optionsInYaml.getWorkerPoolName());
        options.setWorkerPoolSize(optionsInYaml.getWorkerPoolSize());

        return options;
    }
}
